home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Animation Wizard.dir / 00004_Script_IncrDecrValue < prev    next >
Text File  |  1997-05-10  |  5KB  |  159 lines

  1. -- IncrDecrValue script
  2.  
  3. property iType -- #int or #real
  4. property iMin
  5. property iMax
  6. property iInc
  7. property ichField
  8. property ichButton
  9. property iLastValidValue
  10. property iFieldName
  11. property iCastNumNormal
  12. property iCastNumIncr
  13. property iCastNumDecr
  14.  
  15. on birth me, type, min, max, incAmount, chText, theFieldName
  16.   set iType = type
  17.   set iMin = min
  18.   set iMax = max
  19.   set iInc = incAmount
  20.   set ichField = chText
  21.   set ichButton = ichField + 1
  22.   set iLastValidValue = iMin
  23.   set iFieldName = theFieldName
  24.   mSetValue(me, iLastValidValue)
  25.   return me
  26. end birth
  27.  
  28. on mHit me
  29.   -- Assumes that the increment version of the button is one past
  30.   -- the normal state, and the decrement version is two past the
  31.   -- the normal state in the cast.
  32.   set castNumNormal = the castnum of sprite ichButton
  33.   set iCastNumNormal = castNumNormal
  34.   set iCastNumIncr = castNumNormal + 1
  35.   set iCastNumDecr = castNumNormal + 2
  36.   
  37.   set iLastValidValue = field ( the castNum of sprite ichField)
  38.   set lowerLimitBeepedFlag = FALSE
  39.   set upperLimitBeepedFlag = FALSE
  40.   
  41.   set mouseDownFlag = TRUE
  42.   set firstTimeFlag = TRUE
  43.   repeat while mouseDownFlag
  44.     if rollOver(ichButton) then
  45.       
  46.       set okToChangeValueFlag = TRUE
  47.       
  48.       if the mouseV <= the locV of sprite ichButton then  -- upper half of rocker control = increase
  49.         set lowerLimitBeepedFlag = FALSE
  50.         set sign = 1
  51.         if (iLastValidValue = iMax) then --  at upper limit
  52.           set okToChangeValueFlag = FALSE
  53.           if not(upperLimitBeepedFlag) then
  54.             beep
  55.             set upperLimitBeepedFlag = TRUE
  56.             set the castNum of sprite ichButton = castNumNormal
  57.             updateStage
  58.           end if
  59.         end if        
  60.         
  61.       else -- lower  half of rocker control = decrease
  62.         set upperLimitBeepedFlag = FALSE
  63.         set sign = -1
  64.         if (iLastValidValue = iMin) then --  at lower limit
  65.           set okToChangeValueFlag = FALSE
  66.           if not(lowerLimitBeepedFlag) then
  67.             beep
  68.             set lowerLimitBeepedFlag = TRUE
  69.             set the castNum of sprite ichButton = castNumNormal
  70.             updateStage
  71.           end if
  72.         end if
  73.       end if  -- check for upper or lower half of rocker
  74.       
  75.       if okToChangeValueFlag then
  76.         mChangeValue(me, sign)
  77.       end if
  78.       
  79.     else  -- not currently rolled over the button
  80.       set the castNum of sprite ichButton = castNumNormal
  81.       updateStage
  82.     end if 
  83.     
  84.     if firstTimeFlag then  -- this allows for easy one step increments
  85.       set firstTimeFlag = FALSE
  86.       wait(15)
  87.     end if    
  88.     set mouseDownFlag = the mouseDown
  89.     
  90.   end repeat  
  91.   set the castNum of sprite ichButton = castNumNormal
  92.   updateStage
  93. end mHit
  94.  
  95.  
  96.  
  97. on mChangeValue me, sign
  98.   
  99.   if sign = 1 then
  100.     set the castNum of sprite ichButton = iCastNumIncr 
  101.   else
  102.     set the castNum of sprite ichButton = iCastNumDecr
  103.   end if
  104.   updateStage
  105.   
  106.   -- next figure out what the next value ( in the indicated direction ) within the 
  107.   -- appropriate domain is going to be
  108.   
  109.   if iType = #int then
  110.     set iLastValidValue = (integer( iLastValidValue / iInc ) * iInc ) + ( iInc * sign )
  111.   else if iType = #real then
  112.     set iLastValidValue = (( iLastValidValue / iInc ) * iInc ) + ( iInc * sign )
  113.   end if
  114.   -- finally, insert the new value ( properly formatted ) into the field
  115.   put iLastValidValue into field ( the castNum of sprite ichField)  
  116.   
  117. end mChangeValue
  118.  
  119. on mGetValue me
  120.   set theTypedInString = the text of field iFieldName
  121.   set newValue = value(theTypedInString)
  122.   if iLastValidValue <> newValue then  -- user typed in something new
  123.     set iLastValidValue = newValue
  124.   end if
  125.   
  126.   return iLastValidValue
  127. end mGetValue
  128.  
  129. on mSetValue me, theNewValue
  130.   if (theNewValue < iMin) or (theNewValue > iMax) then
  131.     alert("Bad value passed to IncrDecrValue:"  && theNewValue)
  132.     return
  133.   end if
  134.   set iLastValidValue = theNewValue
  135.   set the text of field iFieldName = string(iLastValidValue)
  136.   updateStage
  137. end mSetValue
  138.  
  139. on mValidate me
  140.   
  141.   set theTypedInString = the text of field iFieldName
  142.   set newValue = value(theTypedInString)
  143.   if voidP(newValue) then -- not numeric
  144.     alert("The value in the " & iFieldName & " field must be numeric")
  145.     mSetValue(me, iMin)
  146.     return FALSE
  147.   end if
  148.   if (newValue > iMax) or (newValue < iMin) then
  149.     alert("Please enter a value between " & iMin & " and " & iMax & " into the " &¼
  150.               iFieldName & " field.")
  151.     mSetValue(me, iMin)
  152.     return FALSE
  153.   end if
  154.   
  155.   return TRUE
  156.   
  157. end mValidate
  158.  
  159.